/**
 * 下载文件
 */
@PreAuthorize("@ss.hasPermi('system:business:query')")
@GetMapping("/download-file")
public void downloadFile(@RequestParam("filePath") String filePath, HttpServletResponse response) throws IOException {
    try {
        logger.info("收到下载请求，原始路径: {}", filePath);
        
        // 构建完整路径
        String fullPath = "";
        
        // 检查是否已经包含business目录
        if (filePath.startsWith("business/")) {
            fullPath = RuoYiConfig.getProfile() + "/" + filePath;
        } else {
            // 如果不包含business目录，添加
            fullPath = RuoYiConfig.getProfile() + "/business/" + filePath;
        }
        
        logger.info("构建的完整文件路径: {}", fullPath);
        
        File file = new File(fullPath);
        logger.info("文件是否存在: {}, 是否为文件: {}, 文件大小: {}", 
            file.exists(), file.isFile(), file.exists() ? file.length() : 0);
        
        if (!file.exists()) {
            logger.error("文件不存在: {}", fullPath);
            
            // 尝试其他可能的路径
            String alternatePath = RuoYiConfig.getProfile() + "/" + filePath;
            File alternateFile = new File(alternatePath);
            logger.info("尝试备用路径: {}, 文件存在: {}", alternatePath, alternateFile.exists());
            
            if (alternateFile.exists()) {
                file = alternateFile;
                fullPath = alternatePath;
                logger.info("在备用路径找到文件: {}", fullPath);
            } else {
                response.setContentType("text/plain;charset=UTF-8");
                response.getWriter().write("文件不存在或已被删除");
                return;
            }
        }
        
        // 获取原始文件名
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        
        logger.info("准备下载文件: {}, 文件名: {}", fullPath, fileName);
        
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Disposition", "attachment; filename=" + 
            URLEncoder.encode(fileName, "UTF-8"));
        
        FileUtils.writeBytes(fullPath, response.getOutputStream());
        logger.info("文件下载成功: {}", fileName);
    } catch (Exception e) {
        logger.error("文件下载失败", e);
        response.setContentType("text/plain;charset=UTF-8");
        response.getWriter().write("文件下载失败：" + e.getMessage());
    }
} 